/* 
 * Memories Version 1.0
 * Developed by Jigar Desai (http://www.jigar.net/) 
 */
using System;
using System.Web;


namespace Memories
{
    /// <summary>
    /// Interface for UrlFormatting.
    /// </summary>
    public interface IUrlFormatter
    {
        string GetFolderViewUrl(string path);
        string GetFolderViewPagerTemplate(string path);
        string GetImageViewUrl(string path);
        string GetImageUrl(string path,int size);
        string Decrypt(string output);
    }

    /// <summary>
    /// Default UrlFormatter.
    /// </summary>
    public class SimpleUrlFormatter : IUrlFormatter
    {


        public string GetFolderViewUrl(string path)
        {
            return Utilities.ApplicationPath + "folderview.aspx?path=" + Encrypt(path) + "&";
        }

        public string GetFolderViewPagerTemplate(string path){
            return "<a href=\"" + GetFolderViewUrl(path) + "&amp;page={0}\" >[{1}]</a>";

        }

        public string GetImageViewUrl(string path)
        {
            return Utilities.ApplicationPath + "imageview.aspx?path=" + Encrypt(path);
        }

        public string GetImageUrl(string path, int size)
        {
            if (size > 0)
            {
                return string.Format(Utilities.ApplicationPath + "image.ashx?imagewidth={1}&amp;path={0}", Encrypt(path), size);
            }
            else
            {
                return string.Format(Utilities.ApplicationPath + "image.ashx?path={0}", Encrypt(path));
            }
        }

        public string Encrypt(string input)
        {
            return HttpContext.Current.Server.UrlEncode(input.TrimEnd('/')+"/");
        }

        public string Decrypt(string input)
        {
            return HttpContext.Current.Server.UrlDecode(input);
        }

       
    }

}

